package LanQiaoCompetition.LanQiaoCompetition2;

//回形取数 循环标记
public class Basic_25 {

    private static int ply = 0;
    private static int n =5;
    private static int[][] numbers = new int[n][n];

    public static void main(String[] args){
        //初始化数组
        for(int row = 0;row<n;row++){
            for (int col=0;col<n;col++){
                numbers[row][col]= (int) (Math.random()*10);
            }
        }
        //遍历输出数组
        for(int row = 0;row<n;row++){
            for (int col=0;col<n;col++){
                System.out.print(numbers[row][col]+"  ");
            }
            System.out.println();
        }
        print(0);
    }

    //回形取数 参数0，1，2，3分别代表 下，右，上，左四个方向
    private static void print(int direction){
        if(ply>n/2){
            return;
        }
        switch (direction){
            case 0:
                for (int row=ply;row<n-ply-1;row++){
                    System.out.print(numbers[row][ply]+" ");
                }
                break;
            case 1:
                for (int col=ply;col<n-ply-1;col++){
                    System.out.print(numbers[n-ply-1][col]+" ");
                }
                break;
            case 2:
                for (int row=n-ply-1;row>=ply;row--){
                    System.out.print(numbers[row][n-ply-1]+" ");
                }
                break;
            case 3:
                for (int col=n-ply-2;col>ply;col--){
                    System.out.print(numbers[ply][col]+" ");
                }
                break;
        }
        direction++;
        if(direction==4){
            direction=0;
            ply++;
        }
        print(direction);
    }
}
